package ar.edu.uba.fi.jmit.monitorengine.core.rangeobserver;

import ar.edu.uba.fi.jmit.monitorengine.core.Monitor;
import ar.edu.uba.fi.jmit.monitorengine.core.monitor.AverageMethodTimeMonitor;
import ar.edu.uba.fi.jmit.monitorengine.exception.MonitorEngineRuntimeException;

/**
 * Rango para monitoreos de tipo {@link AverageMethodTimeMonitor}.
 * @author Tomas
 *
 */
public class AverageMethodTimeRangeObserver extends MethodTimeRangeObserver {

	/**
	 * Devuelve el methodTime
	 */
	@Override
	protected Long getMonitorActualValue(Monitor monitor) {
		return getMethodTimeMonitor(monitor).getAverage().longValue();
	}

	/**
	 * Verifica que el monitor sea del tipo esperado y lo castea.
	 * @param monitor
	 * @return
	 */
	private AverageMethodTimeMonitor getMethodTimeMonitor(Monitor monitor) {
		if(!(monitor instanceof AverageMethodTimeMonitor)) {
			throw new MonitorEngineRuntimeException("A AverageMethodTimeRangeObserver Observer can only observ a AverageMethodTimeMonitor");
		}
		return (AverageMethodTimeMonitor)monitor;
	}
}
